package com.xinyin.aiqinhaiback.exception;

import com.xinyin.aiqinhaiback.common.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;


@RestControllerAdvice
public class MyExceptionAdvice {

    private static final Logger logger = LoggerFactory.getLogger(MyExceptionAdvice.class);

    /**
     * 处理与用户相关的业务异常
     * @return
     */
    @ExceptionHandler(MyException.class)
    public ResponseResult UserExceptionHandler(HttpServletRequest request, MyException e){
        logger.info("业务异常：Host:{} invoke URL:{},错误信息：{}",request.getRemoteHost(),request.getRequestURL(),e.getMessage());
        return new ResponseResult(e.getCode(),e.getMessage());
    }

}
